package uk.org.landeg.euler.problems;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;

import uk.org.landeg.euler.problems.framework.AbstractProblem;
import uk.org.landeg.euler.problems.framework.ProblemLauncher;

public class Problem099 extends AbstractProblem {
	public static void main(String[] args) {
		ProblemLauncher launcher = new ProblemLauncher(new Problem099());
		launcher.solve();
	}

	@Override
	public String getDescription() {
		// TODO Auto-generated method stub
		return "determine which line number has the greatest numerical value";
	}

	@Override
	public Integer getProblemNumber() {
		// TODO Auto-generated method stub
		return 99;
	}

	@Override
	public Object solve() {
		BufferedReader reader = null;
		try {
			reader = new BufferedReader (new FileReader ("data/base_exp.txt"));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		notes.add("These numbers are way too big to handle efficiently, we only need a maxima, max (a^b) is same as log10(max(a^b))");
		notes.add("take logs of these values so a^b -> b * log10(a)");
		notes.add("Approx running time : 100ms");
		String line;
		int maxLine= 0;
		int lineNumber = 1;
		double maxVal = 0.0, currentVal;
		Matcher m;
		int a, b;
		String nums[];
		try {
			while ((line = reader.readLine()) != null) {
				nums = line.split(",");
				a=Integer.parseInt(nums[0]);
				b=Integer.parseInt(nums[1]);
				currentVal = b * Math.log10(a);
				if (currentVal > maxVal) {
					System.out.println("new maxima, line " + lineNumber + "\t" + line);
					maxLine = lineNumber;
					maxVal = currentVal;
				}
				lineNumber++;
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return maxLine;
	}

}
